package com.ruoyi.web.controller.mdm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mdm.domain.SkuMetricsScore;
import com.ruoyi.mdm.service.ISkuMetricsScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品指标得分Controller
 *
 * @author shiseido
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/mdm/skuMetricsScore")
public class SkuMetricsScoreController extends BaseController {
    @Autowired
    private ISkuMetricsScoreService skuMetricsScoreService;

    /**
     * 查询产品指标得分列表
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkuMetricsScore skuMetricsScore) {
        startPage();
        List<SkuMetricsScore> list = skuMetricsScoreService.selectSkuMetricsScoreList(skuMetricsScore);
        return getDataTable(list);
    }

    /**
     * 导出产品指标得分列表
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:export')")
    @Log(title = "产品指标得分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuMetricsScore skuMetricsScore) {
        List<SkuMetricsScore> list = skuMetricsScoreService.selectSkuMetricsScoreList(skuMetricsScore);
        ExcelUtil<SkuMetricsScore> util = new ExcelUtil<SkuMetricsScore>(SkuMetricsScore.class);
        util.exportExcel(response, list, "产品指标得分数据");
    }

    /**
     * 获取产品指标得分详细信息
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(skuMetricsScoreService.selectSkuMetricsScoreById(id));
    }

    /**
     * 新增产品指标得分
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:add')")
    @Log(title = "产品指标得分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuMetricsScore skuMetricsScore) {
        return toAjax(skuMetricsScoreService.insertSkuMetricsScore(skuMetricsScore));
    }

    /**
     * 修改产品指标得分
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:edit')")
    @Log(title = "产品指标得分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuMetricsScore skuMetricsScore) {
        return toAjax(skuMetricsScoreService.updateSkuMetricsScore(skuMetricsScore));
    }

    /**
     * 删除产品指标得分
     */
    @PreAuthorize("@ss.hasPermi('mdm:skuMetricsScore:remove')")
    @Log(title = "产品指标得分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(skuMetricsScoreService.deleteSkuMetricsScoreByIds(ids));
    }

    /**
     * 产品指标得分定时任务测试
     */
    @PostMapping("/taskTest")
    public void taskTest() {
        skuMetricsScoreService.calculateSkuMetricsScore();
    }
}
